package cc.git.liuyan.customeraiagent.core.embeddingmodel.abstrct;

import cc.git.liuyan.customeraiagent.core.embeddingmodel.*;

import java.util.List;

public abstract class AbstractEmbeddingModel implements EmbeddingModel {
    private final String name;
    private final int dimension;
    protected final EmbeddingModelApiClient apiClient;
    protected EmbeddingModelSplit split;

    public AbstractEmbeddingModel(String name, int dimension, EmbeddingModelApiClient apiClient) {
        this.name = name;
        this.dimension = dimension;
        this.apiClient = apiClient;
    }

    @Override
    public final String modelName() {
        return this.name;
    }

    @Override
    public final int dimension() {
        return this.dimension;
    }

    @Override
    public final void setSplit(EmbeddingModelSplit split) {
        this.split = split;
    }

    @Override
    public final EmbeddingModelSplit getSplit() {
        return this.split;
    }

    @Override
    public List<EmbeddingModelOutputData> embed(EmbeddingModelInputData inputData) {
        if (this.split == null) {
            this.split = new SimpleEmbeddingModelSplit();
        }
        //不管输入是什么类型，分片后segment数据都是type=string
        List<EmbeddingModelInputData> inputDataSegmentList = split.split(inputData);
        return this.embedFinal(inputDataSegmentList);
    }

    protected abstract List<EmbeddingModelOutputData> embedFinal(List<EmbeddingModelInputData> inputDataSegmentList);
}
